(function(){"use strict";var E=Object.defineProperty;var m=(i,e,t)=>e in i?E(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var c=(i,e,t)=>m(i,typeof e!="symbol"?e+"":e,t);const p="https://web.whatsapp.com",s=class s{constructor(){c(this,"observer");c(this,"intersectionObserver");c(this,"debounceTimeout",null);this.observer=new MutationObserver(this.handleMutations.bind(this)),this.intersectionObserver=new IntersectionObserver(this.handleIntersection.bind(this),{rootMargin:"100px"})}handleIntersection(e){e.forEach(t=>{t.isIntersecting&&this.handleContactElement(t.target)})}handleContactElement(e){try{const t=this.getReactFiber(e),n=this.getContactIdFromReactFiber(t);n&&(e.setAttribute("data-contact-id",n),window.parent.postMessage({type:"contactIdDetected",contactId:n},p))}catch(t){console.error("Error handling contact element:",t)}}getReactFiber(e){try{const t=Object.keys(e).find(n=>n.startsWith("__reactFiber$"));return t?e[t]:null}catch(t){return console.error("Error getting React Fiber:",t),null}}getContactIdFromReactFiber(e){try{const t=r=>{var a,h;const o=((a=r==null?void 0:r.memoizedProps)==null?void 0:a.id)??((h=r==null?void 0:r.pendingProps)==null?void 0:h.id);if(o&&typeof o=="object"&&typeof o.user=="string"){const l=o.user;return l.startsWith("chat-")?l.replace("chat-",""):l}return null},n=[{node:e,depth:0}],b=40;for(;n.length>0;){const{node:r,depth:o}=n.pop();if(!r||o>b)continue;const a=t(r);if(a)return a;r.sibling&&n.push({node:r.sibling,depth:o}),r.child&&n.push({node:r.child,depth:o+1})}return console.warn("[domObserver] contactId NOT found. fiberNode root:",e),null}catch(t){return console.error("Error getting contact ID from React Fiber:",t),null}}handleMutations(){this.debounce(()=>{this.processContactElements()})}handleScroll(){this.debounce(()=>{this.processContactElements()})}processContactElements(){try{document.querySelectorAll(s.CONTACT_LIST_SELECTOR).forEach(t=>{this.intersectionObserver.observe(t)})}catch(e){console.error("Error processing contact elements:",e)}}debounce(e,t=500){this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(e,t)}start(){try{const e=document.querySelector(s.PANE_SELECTOR);e?(this.observer.observe(e,{childList:!0,subtree:!0,attributeFilter:["style"]}),e.addEventListener("scroll",this.handleScroll.bind(this)),this.processContactElements()):console.warn("Pane side element not found")}catch(e){console.error("Error starting observer:",e)}}stop(){const e=document.querySelector(s.PANE_SELECTOR);e&&e.removeEventListener("scroll",this.handleScroll.bind(this)),this.observer.disconnect(),this.intersectionObserver.disconnect(),this.debounceTimeout=null}};c(s,"CONTACT_LIST_SELECTOR","#pane-side div.x1n2onr6 > div[tabindex]"),c(s,"PANE_SELECTOR","#pane-side");let d=s;const u=new d;u.start();window.addEventListener("unload",()=>{u.stop()});
})();